﻿using System;
using System.Threading;
using CodingDay.Rx.Shared.Domain;
using CodingDay.Rx.Shared.Events;
using CodingDay.Rx.Shared.Interfaces;

namespace CodingDay.Rx.Adaptors
{
    public class ServerFeedAdaptor : IServerFeedAdaptor
    {
        //private TcpClient Client { get; set; }
        //private string Host { get; set; }
        //private int Port { get; set; }
        private bool ContinueReadingStream { get; set; }

        #region IServerFeedAdaptor Members

        public event DTOReceived OnDataReceived;

        #endregion


        public void Start()
        {
            //Client = new TcpClient();
            //Client.Connect(Host, Port);

            //using (NetworkStream networkStream = Client.GetStream())
            //{
            //    while (ReadStream)
            //    {
            //        //TODO: Parse Stream
            //        //TODO: Fire Event
            //    }
            //}

            ContinueReadingStream = true;

            //Fake Create
            while (ContinueReadingStream)
            {
                if (OnDataReceived != null) 
                    OnDataReceived(this, new DTOReceivedArgs("FakeHost", "FakePort", new DTO()));
                
                Thread.Sleep(10);
            }
        }

        public void Stop()
        {
            ContinueReadingStream = false;
        }
    }
}